//
//  DiaryEditPhotosTableViewCell.swift
//  MoodDiary
//
//  Created by ext.tanjian3 on 2022/1/24.
//

import UIKit

class DiaryEditPhotosTableViewCell: UITableViewCell {

    
    @IBOutlet weak var photoCollectionView: UICollectionView!
    
    var photoArr: [UIImage]?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        photoCollectionView.delegate = self
        photoCollectionView.dataSource = self
        photoCollectionView.register(UINib(nibName: "DiaryEditPhotoCollectionViewCell", bundle: .main), forCellWithReuseIdentifier: "DiaryEditPhotoCollectionViewCell")
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}

extension DiaryEditPhotosTableViewCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        return CGSize(width: 60, height: 60)
    }

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {

        return 0.0
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
        
        return 0.0
    }
    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
        return UIEdgeInsets.init(top: 10, left: 30, bottom: 10, right: 30)
    }
    
    
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

        return photoArr?.count ?? 0
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
            let cell: DiaryEditPhotoCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "DiaryEditPhotoCollectionViewCell", for: indexPath) as! DiaryEditPhotoCollectionViewCell
        
        cell.photoImgView.image = photoArr?[indexPath.item]
        
        return cell
        
    }
    
}
